package com.example.filecabinet.service;

import com.example.filecabinet.dto.StaffMemberInfo;
import com.example.filecabinet.dto.resp.GeneralUserQueryResp;
import com.example.filecabinet.dto.resp.StaffMemberQueryResp;
import com.example.filecabinet.util.Http;
import com.thfdcsoft.framework.common.http.dto.BaseHttpRspn;
import com.thfdcsoft.framework.common.json.jackson.JacksonFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Random;

@Service("staffMemberService")
public class StaffMemberService {
    //获取工作人员查询接口
    @Value("${staffMemberQueryUrl}")
    private String queryUrl;


    public String staffMemberUrl(String staffMemberQueryReq) {

        //随机生成一个业务编号
        String num = "";
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            num += String.valueOf(random.nextInt(10));
        }


        //正式环境
//      String json = Http.sendPost(queryUrl,staffMemberQueryReq);
        //测试数据
        String testJson = "{\"code\":\"1\",\"message\":\"\",\"data\":{\"businessNumber\":\"123456789\",\"businessType\":\"登记证明\",\"userName\":\"张三\",\"userNumber\":\"420622198003294839\",\"userTel\":\"13098451801\"}}";
        StaffMemberQueryResp staffMemberQueryResp = JacksonFactory.readJson(testJson, StaffMemberQueryResp.class);
        //封装返回对象
        BaseHttpRspn result = new BaseHttpRspn(false);
        if (staffMemberQueryResp.getCode() == "1" || staffMemberQueryResp.getCode().equals("1")) {
            result.setResult(true);
            //测试数据
            StaffMemberInfo staffMemberInfo = new StaffMemberInfo();
            staffMemberInfo.setBusinessNumber(num);
            staffMemberInfo.setBusinessType("登记证明");
            staffMemberInfo.setUserName("张三");
            staffMemberInfo.setUserTel("13098451801");
            result.setRespJson(JacksonFactory.writeJson(staffMemberInfo));

//            result.setRespJson(JacksonFactory.writeJson(staffMemberQueryResp.getData()));
            result.setRespMsg("查询成功");
            System.out.println(JacksonFactory.writeJson(staffMemberQueryResp.getData()));
            return JacksonFactory.writeJson(result);
        } else {
            result.setResult(false);
            result.setRespJson(JacksonFactory.writeJson(staffMemberQueryResp.getData()));
            result.setRespMsg("未查询到数据");
            return JacksonFactory.writeJson(result);
        }
    }

}
